home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John Noland)
- Newsgroups: comp.lang.c
- Subject: Re: problem w/ realloc
- Date: 21 Mar 1996 20:20:18 GMT
- Organization: Prose Software
- Distribution: usa
- Message-ID: <4isdm2$a44@newshost.cyberramp.net>
- References: <4iqef0$dqq@montana.avicom.net>
- NNTP-Posting-Host: ramp1-21.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <4iqef0$dqq@montana.avicom.net>, zoot@montana.avicom.net says...
- >
- >I've been porting a piece of code from AIX 3.2.5 to linux 1.2.8
- >(gcc 2.7.0) recently, and finaly chased down the last :-) bug. The code
- >assumes that if you have a memory block, and you realloc it smaller, it
- >doesn't move the block of memory, it just makes the "usable size" of it
- >smaller. (in fact, my textbook ("advanced programming in the unix
- >environment" stevens) supports this usage) unfortunately, xxgdb has
- >revealed that the realloc is moving my pointer! am I mistaken about the
- >standards, or is this a special case I'm not aware of?
- >any help appreciated-
-
- It is not a special case. realloc() adjusts the size of the allocated block
- to the size you pass, copying the contents to a new location if necessary.
- Therefore, because the new block can be in a new memory location, the pointer
- returned by realloc() is *NOT* guaranteed to be the pointer passed into it.
-
- -John
-
-